/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taganalysistoolsclient;

import elaborate.tag_analysis.model.Resource;
import elaborate.tag_analysis.restws.client.ResourceDao;
import java.util.List;
import java.util.UUID;

/**
 *
 * @author lendle
 */
public class TagAnalysisToolsClient3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        ResourceDao dao=new ResourceDao("http://taganalysis.appspot.com/rest/resource");
        Resource resource=new Resource();
        resource.setApplicationId("1");
        resource.setId(UUID.randomUUID().toString());
        resource.setParentResourceId("1");
        dao.newResource(new Resource[]{resource});
        System.out.println("new: "+resource);
        resource.setName("hahaha");
        dao.updateResource(resource);
        dao.deleteResource("1", resource.getId());
        List<Resource> list=dao.findAll("1");
        System.out.println(list.size());
        list=dao.findByParentResourceId("1", "1");
        System.out.println(list.size());
        resource=dao.findById("1", "df473a3e-603d-4005-8776-985b1bf4c14a");
        System.out.println(resource);
//        ClientConfig config = new DefaultClientConfig();
//        Client client = Client.create(config);
//        WebResource service = client.resource("http://taganalysis.appspot.com");
//        Form form = new Form();
//        form.add("id", ""+UUID.randomUUID().toString());
//        form.add("name", "test1");
//        form.add("value", "");
//        form.add("applicationId", "1");
//        form.add("parentResourceId", "1");
//        ClientResponse response = service.path("rest").path("resource").accept(MediaType.APPLICATION_JSON).post(ClientResponse.class, form);
//        Resource resource=response.getEntity(Resource.class);
//        resource.setName("hahaha");
//        service.path("rest").path("resource").accept(MediaType.APPLICATION_JSON).put(Resource.class, resource);
//        service.path("rest").path("resource").path("1").path(URLEncoder.encode(""+resource.getId(), "utf-8")).delete();
//        response= service.path("rest").path("resource").path("1").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//        Resource [] resources=response.getEntity(Resource[].class);
//        System.out.println(resources.length);
//        response= service.path("rest").path("resource").path("1").path("df473a3e-603d-4005-8776-985b1bf4c14a").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
//        System.out.println(response.getEntity(Tag.class).getName());
    }
}
